package com.wnhz.work.jy.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.wnhz.work.jy.R;
import com.wnhz.work.jy.bean.BankCardBean;

import java.util.List;

/**
 * Created by d on 2016/10/8.
 */
public class BankCardAdapter extends BaseAdapter{
    private Context context;
    private List<BankCardBean> lists;

    private boolean select;

    private int index;

    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    public boolean isSelect() {
        return select;
    }

    public void setSelect(boolean select) {
        this.select = select;
    }

    public BankCardAdapter(Context context, List<BankCardBean> lists) {
        this.context = context;
        this.lists = lists;
    }

    @Override
    public int getCount() {
        return lists.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        MyHolder holder;
        if (view == null){
            view = LayoutInflater.from(context).inflate(R.layout.bank_card_listview_item,null);
            holder = new MyHolder();
            holder.bank_card_name = (TextView) view.findViewById(R.id.bank_card_name);
            holder.bank_card_number = (TextView) view.findViewById(R.id.bank_card_number);
            holder.img = (ImageView) view.findViewById(R.id.img);
            holder.lay1 = view.findViewById(R.id.lay1);
            view.setTag(holder);
        }
        holder = (MyHolder) view.getTag();

        if (select){
            holder.img.setVisibility(View.VISIBLE);
            holder.lay1.setVisibility(View.GONE);
            if (index == i){
                holder.img.setImageResource(R.mipmap.ic_xuanze31_li);
            }else {
                holder.img.setImageResource(R.mipmap.ic_xuanze_nor);
            }
        }else {
            holder.lay1.setVisibility(View.GONE);
            holder.img.setVisibility(View.GONE);
        }
        holder.bank_card_name.setText(lists.get(i).getBankName()+"   "+lists.get(i).getBranch());
        holder.bank_card_number.setText(lists.get(i).getBankCardNumber());
        return view;
    }

    private class MyHolder{
        TextView bank_card_name;
        TextView bank_card_number;
        ImageView img;
        View lay1;

    }
}
